package application;

import java.net.URL;
import java.util.ResourceBundle;

import base.Bulletin;
import base.Loadperson;
import base.Manager;
import base.Person;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;

import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.TableColumn;

public class NamelistController implements Initializable{
	@FXML
	private Button bcheckattendance;
	@FXML
	private Button bstaffinfo;
	@FXML
	private Button battendance_st;
	@FXML
	private Button bdaily_ass;
	@FXML
	private Button bbulletin;
	@FXML
	private Button blogout;
	@FXML
	private TableView bulletinlist;
	@FXML
	private TableColumn id;
	@FXML
	private TableColumn name;
	@FXML
	private Button showown;
	
    static Main application;
    
    static Manager p= new Manager();
    
    @FXML
	public void toOwnchart(ActionEvent event){
		String s = String.valueOf(p.getID());
		application.gotoworkdayinfo(p, s);
	}
	
	
	public void setApp(Main application){  
        this.application = application;
        ObservableList<TableColumn<Loadperson,?>> observableList = bulletinlist.getColumns();
        observableList.get(0).setCellValueFactory(new PropertyValueFactory("id"));
        observableList.get(1).setCellValueFactory(new PropertyValueFactory("name"));
        bulletinlist.setItems(db.DB_tools.getNamelist());
        id.setCellFactory(new TaskCellFactory());//go to taskcellfactory including the action.    	
        }
	
	public static void toworkchart(String id){
		application.gotoworkdayinfo(p,id);
		
	}
	
	@FXML
	public void bbulletin(ActionEvent event){
		if("Manager".equals(p.getLevel())){
		    Manager m = (Manager)p;
			application.gotoaddBulletin(m);
		}
		else{
			application.gotoBulletin(p);
		}
		
	}
	
	@FXML
	public void gotoAssignment(ActionEvent event)
	{
		if("Manager".equals(p.getLevel()))
		{
			Manager m=(Manager)p;
			application.gotoaddAssignment(m);
		}
		else{
			application.gotoAssignment(p);
		}
	}
	
	@FXML
	public void bcheckattendance(ActionEvent event)
	{
		application.gotoCheckAttendance(p);	
	}
	

	@FXML
	public void bstaffinfo(ActionEvent event)
	{
		if("Manager".equals(p.getLevel()))
		{
			Manager m=(Manager)p;
			System.out.println("I'm Manager");
			application.gotoNamelist(m);
		}
		else
		{
			application.gotoStaffinfo(p);
		}
	}
	
	@FXML
	public void bdaily_ass(ActionEvent event)
	{
		if("Manager".equals(p.getLevel())){
		    Manager m = (Manager)p;
			application.gotoaddAssignment(m);
		}
		else{
			application.gotoAssignment(p);
		}
	}
	
	@FXML
	public void battendance_st(ActionEvent event){
		if("Manager".equals(p.getLevel())){
		    Manager m = (Manager)p;
			application.gotonamelist(m);
		}
		else{
			String s = String.valueOf(p.getID());
			application.gotoworkdayinfo(p, s);
		}
	}

	
	
	@Override
	public void initialize(URL location, ResourceBundle resources) {
		// TODO Auto-generated method stub
		
	}

}
